package com.zhuhao.basic.myenum;

/**
 * 枚举中valus（）方法不是继承而来，时代码编译时编译器插入的静态方法
 *
 * @Author zhuhao
 * @Date 2021/7/22 0022 16:19
 * @desc
 */
public enum ColorEnum02 implements Person{
    RED("红色", 1),
    GREEN("绿色", 2),
    BLACK("黑色", 3),
    BLANK("白色", 4),
    YELLOW("黄色", 5);

    private String name;
    private int index;

    ColorEnum02(String name, int index) {
    }

    public static String getName(int index) {
        ColorEnum02[] values = ColorEnum02.values();
        for (ColorEnum02 value : values) {
            if (value.index == index) {
                return value.name;
            }
        }
        return null;
    }

    // get set 方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    @Override
    public String toString() {
        return this.name + "_" + this.index;
    }

    @Override
    public void print() {
        System.out.println(this.name + "_" + this.index);
    }

    @Override
    public String getInfo() {
        return this.name;
    }
}
